package com.buaa.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.buaa.dto.UserExtensionActivityDTO;
import com.buaa.entity.UserExtensionActivity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserExtensionActivtyMapper extends BaseMapper<UserExtensionActivity> {



    @Select("select police_user.police_id, police_user.user_name, ext.id as id,\n" +
            "       police_user.id as userId, ext.gender, ext.date_of_birth as dateOfBirth,\n" +
            "       ext.join_date as joinDate, ext.police_rank as policeRank, ext.department as department,\n" +
            "       ext.duty_station as dutyStation, ext.phone_number as phoneNumber, ext.home_address as homeAddress,\n" +
            "       ext.emergency_contact_name as emergencyContactName, ext.emergency_contact_phone as emergencyContactPhone,\n" +
            "       ext.is_active as isActive, ext.police_province as policeProvince, ext.police_city as policeCity,\n" +
            "       ext.revision_time as revisionTime, ext.reviser as reviser, ext.operation_type as operationType from police_user_extension_activity ext\n" +
            "left join police_user on police_user.id = ext.user_id " +
            "where police_user.police_id like CONCAT('%', #{policeId}, '%') and " +
            "police_user.user_name like CONCAT('%', #{userName}, '%')  " +
            "order by ext.create_time desc LIMIT #{pageNum}, #{pageSize}")
    List<UserExtensionActivityDTO> getUserList(@Param("policeId") String policeId, @Param("userName") String userName, Integer pageNum, Integer pageSize);

    @Select("select police_user.police_id, police_user.user_name, ext.id as id,\n" +
            "       police_user.id as userId, ext.gender, ext.date_of_birth as dateOfBirth,\n" +
            "       ext.join_date as joinDate, ext.police_rank as policeRank, ext.department as department,\n" +
            "       ext.duty_station as dutyStation, ext.phone_number as phoneNumber, ext.home_address as homeAddress,\n" +
            "       ext.emergency_contact_name as emergencyContactName, ext.emergency_contact_phone as emergencyContactPhone,\n" +
            "       ext.is_active as isActive, ext.police_province as policeProvince, ext.police_city as policeCity,\n" +
            "       ext.revision_time as revisionTime, ext.reviser as reviser, ext.operation_type as operationType  from police_user_extension_activity ext\n" +
            "left join police_user on police_user.id = ext.user_id " +
            "where police_user.police_id like CONCAT('%', #{policeId}, '%') " +
            "order by ext.create_time desc LIMIT #{pageNum}, #{pageSize}")
    List<UserExtensionActivityDTO> getUserListByPid(@Param("policeId")String policeId, Integer pageNum, Integer pageSize);

    @Select("select police_user.police_id, police_user.user_name, ext.id as id,\n" +
            "       police_user.id as userId, ext.gender, ext.date_of_birth as dateOfBirth,\n" +
            "       ext.join_date as joinDate, ext.police_rank as policeRank, ext.department as department,\n" +
            "       ext.duty_station as dutyStation, ext.phone_number as phoneNumber, ext.home_address as homeAddress,\n" +
            "       ext.emergency_contact_name as emergencyContactName, ext.emergency_contact_phone as emergencyContactPhone,\n" +
            "       ext.is_active as isActive, ext.police_province as policeProvince, ext.police_city as policeCity,\n" +
            "       ext.create_time as createTime, ext.create_by as createBy, ext.revision_time as revisionTime, ext.reviser as reviser, ext.operation_type as operationType  from police_user_extension_activity ext\n" +
            "left join police_user on police_user.id = ext.user_id " +
            "order by ext.revision_time desc LIMIT #{pageNum}, #{pageSize}")
    List<UserExtensionActivityDTO> getUserListByDefault(Integer pageNum, Integer pageSize);

    @Select("select police_user.police_id, police_user.user_name, ext.id as id,\n" +
            "       police_user.id as userId, ext.gender, ext.date_of_birth as dateOfBirth,\n" +
            "       ext.join_date as joinDate, ext.police_rank as policeRank, ext.department as department,\n" +
            "       ext.duty_station as dutyStation, ext.phone_number as phoneNumber, ext.home_address as homeAddress,\n" +
            "       ext.emergency_contact_name as emergencyContactName, ext.emergency_contact_phone as emergencyContactPhone,\n" +
            "       ext.is_active as isActive, ext.police_province as policeProvince, ext.police_city as policeCity,\n" +
            "       ext.revision_time as revisionTime, ext.reviser as reviser, ext.operation_type as operationType  from police_user_extension_activity ext\n" +
            "left join police_user on police_user.id = ext.user_id " +
            "where police_user.user_name like CONCAT('%', #{userName}, '%')  " +
            "order by ext.create_time desc LIMIT #{pageNum}, #{pageSize}")
    List<UserExtensionActivityDTO> getUserListByUserName(@Param("userName") String userName, Integer pageNum, Integer pageSize);

    @Select("select count(1) from police_user_extension_activity ext  left join police_user on police_user.id = ext.user_id")
    Integer getTotal();

    @Select("select count(1) from police_user_extension_activity ext  left join police_user on police_user.id = ext.user_id " +
            "where police_user.police_id like CONCAT('%', #{policeId}, '%')")
    Integer getTotalWithPoliceId(@Param("policeId") String PoliceId);

    @Select("select count(1) from police_user_extension_activity ext  left join police_user on police_user.id = ext.user_id " +
            "where police_user.user_name like CONCAT('%', #{userName}, '%')")
    Integer getTotalWithUserName(@Param("userName") String userName);
}
